// 百度地图API功能
var map = new BMap.Map("allmap");
var point = new BMap.Point(116.331398,39.897445);
map.centerAndZoom(point,12);
//浏览器定位
var geolocation = new BMap.Geolocation();
geolocation.getCurrentPosition(function(r){
    if(this.getStatus() == BMAP_STATUS_SUCCESS){
        var mk = new BMap.Marker(r.point);
        map.addOverlay(mk);
        map.panTo(r.point);
        // alert('您的位置：'+r.point.lng+','+r.point.lat);
        $('#lat').val(r.point.lat);//获取到的纬度
        $('#lon').val(r.point.lng);//获取到的经度

        var gc = new BMap.Geocoder();
        var pointAdd = new BMap.Point(r.point.lng, r.point.lat);
        gc.getLocation(pointAdd, function(rs){
            // 百度地图解析城市名
            $('#pro_num').html(rs.addressComponents.city);
            //或者其他信息
            city = rs.addressComponents.city;
            $.ajax({
                type:"get",
                url:'http://wthrcdn.etouch.cn/weather_mini?city='+city,
                success:function (res) {
                    res = JSON.parse(res);
                    $('#type').html(res.data.forecast[0].type);
                    $('#high').html(res.data.forecast[0].high);
                    $('#low').html(res.data.forecast[0].low);
                    $('#fengxiang').html(res.data.forecast[0].fengxiang);
                    $('#ganmao').html(res.data.ganmao);
                    $('#wendu').html(res.data.wendu);

                }
            })
            //或者其他信息
        })
    }
    else {
        alert('failed'+this.getStatus());
    }
},{enableHighAccuracy: true});

function returnWeather() {
    map.centerAndZoom(point,12);
//浏览器定位
    var geolocation = new BMap.Geolocation();
    geolocation.getCurrentPosition(function(r){
        if(this.getStatus() == BMAP_STATUS_SUCCESS){
            var mk = new BMap.Marker(r.point);
            map.addOverlay(mk);
            map.panTo(r.point);
            // alert('您的位置：'+r.point.lng+','+r.point.lat);
            $('#lat').val(r.point.lat);//获取到的纬度
            $('#lon').val(r.point.lng);//获取到的经度

            var gc = new BMap.Geocoder();
            var pointAdd = new BMap.Point(r.point.lng, r.point.lat);
            gc.getLocation(pointAdd, function(rs){
                // 百度地图解析城市名
                $('#pro_num').html(rs.addressComponents.city);
                //或者其他信息
                city = rs.addressComponents.city;
                $.ajax({
                    type:"get",
                    url:'http://wthrcdn.etouch.cn/weather_mini?city='+city,
                    success:function (res) {
                        res = JSON.parse(res);
                        $('#type').html(res.data.forecast[0].type);
                        $('#high').html(res.data.forecast[0].high);
                        $('#low').html(res.data.forecast[0].low);
                        $('#fengxiang').html(res.data.forecast[0].fengxiang);
                        $('#ganmao').html(res.data.ganmao);
                        $('#wendu').html(res.data.wendu);

                    }
                })
                //或者其他信息
            })
        }
        else {
            alert('failed'+this.getStatus());
        }
    },{enableHighAccuracy: true});
}